package com.wnhz.work.yz.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.utils.Url;

/**
 * ---用户协议
 */
public class AgreementActivity extends BaseActivity implements View.OnClickListener {
    private TextView title;
    private WebView webview;

    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    closeDialog();
                    break;

                default:
                    break;
            }
        }

    };

    @Override
    protected void onDestroy() {
        if (webview != null) {
            webview.clearCache(true);
            webview.onPause();
            webview.destroy();
        }
        super.onDestroy();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agreement);

        initView();
    }

    private void initView() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("用户协议");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        webview = (WebView) findViewById(R.id.webview);
        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(false);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小

        showDialog();
        if (webview != null) {
            webview.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    handler.sendEmptyMessage(1);
                    super.onPageFinished(view, url);
                }
            });
//            webview.getSettings().setJavaScriptEnabled(true);
            webview.loadUrl(Url.GETCLAUSE);
        }

    }

    private static final String TAG = "AgreementActivity";

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;

            default:
                break;
        }
    }
}
